#ifndef LUAOBJECT_H
#define LUAOBJECT_H

template<class T>
class LuaClass
{
  public:
    LuaClass(lua_State* luastate,const char* classname,const char* modulename)
    {
      /*LuaState = luastate;
      if(!mName)
      {
        int len = strlen(classname)+strlen(modulename)+2;
        mName=new char[len];
        if(!mName)
          return ;
        strncpy_s(mName,len,modulename,strlen(modulename));
        mName[strlen(modulename)]='.';
        strncpy_s(mName+strlen(modulename)+1,len-strlen(modulename)-1,classname,strlen(classname));
        RegisterClass(mName);
      }*/
    }
    LuaClass(LuaClass& lclass)
    {
      /*LuaState = lclass.LuaState;*/
    }
    ~LuaClass() {}
  public:
    template<class M> 
    LuaClass& Method(const char* funcname,M m)
    {
      /*CHECKSTACK_BEGIN(LuaState,0);
      luaL_getmetatable(LuaState,mName);
      if(!lua_istable(LuaState,-1))
        return *this;
      LuaStack::StackValue<const char*>::Push(LuaState,funcname);
      LuaStack::StackValue<M>::Push(LuaState,m);
      LuaStack::MethodPush<T,M>::Push(LuaState);
      lua_rawset(LuaState,-3);
      lua_pop(LuaState,1);
	  */
      return *this;
    }
    template<class S>
    LuaClass& Super()
    {
      /*CHECKSTACK_BEGIN(LuaState,0);
      if(!LuaClass<S>::mName)
        return *this;
      luaL_getmetatable(LuaState,mName);
      lua_pushstring(LuaState,"__supermet");
      luaL_getmetatable(LuaState,LuaClass<S>::mName);
      lua_rawset(LuaState,-3);
      lua_pop(LuaState,1);*/
      return *this;
    }
    bool RegisterClass(char* ClassName)
    {
      /*CHECKSTACK_BEGIN(LuaState,0);
      luaL_newmetatable(LuaState,ClassName);
      if(!lua_istable(LuaState,-1))
        return false;
      int tbl = lua_gettop(LuaState);
      LuaStack::StackValue<const char*>::Push(LuaState,"__index");
      lua_pushcclosure(LuaState,__LuaIndexFunc,0);
      lua_settable(LuaState,-3);
      lua_pop(LuaState,1);*/
      return true;
    }
    static int __LuaIndexFunc(lua_State* L)
    {
      /*luaL_getmetatable(L,mName);
      lua_pushvalue(L,-2);
      const char* cn = lua_tostring(L,-1);
      lua_rawget(L,-2);
      while(lua_isnil(L,-1))
      {
        lua_pop(L,1);
        lua_pushstring(L,"__supermet");
        lua_rawget(L,-2);
        if(lua_isnil(L,-1))
        {
          lua_pop(L,2);
          return 0;
        }
        lua_replace(L,-2);
        lua_pushvalue(L,-2);
        lua_rawget(L,-2);
      }
      
      lua_replace(L,-2);*/
      return 1;
    }
    static const char* GetName() {return mName;}
  public: 
    lua_State* LuaState;
    static char* mName;
};
template<class T> char* LuaClass<T>::mName=NULL;

  

#endif //LUAOBJECT_H
